home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17030 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: charnel.ecst.csuchico.edu!csusac!lesneskp
  2. From: lesneskp@ecs.ecs.csus.edu (Paul Lesneski)
  3. Newsgroups: comp.lang.c++
  4. Subject: help on USES relationships (& printer ostream)
  5. Date: 13 Apr 1996 05:12:53 GMT
  6. Organization: California State University, Sacramento
  7. Message-ID: <4knd4l$j7e@csusac.ecs.csus.edu>
  8. NNTP-Posting-Host: gaia.ecs.csus.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Greetings,
  12.  
  13. I have a couple questions that I would greatly appreciate
  14. getting email back on (lesneskp@gaia.ecs.csus.edu).  I 
  15. deeply thank y'all for any help!
  16.  
  17.  
  18. A quickie first:  I need to open an output stream to the
  19. printer, preferably as an ostream object (so I can use
  20. it identically to "cout"), but surprisingly cannot find
  21. any references on how to do so.  I assume this is a
  22. simple task.  Anyone??
  23.  
  24. And...
  25.  
  26. I'm having trouble implementing a "uses" relationship.
  27. A simple analogy would be that we have two unrelated 
  28. classes, cl_a and cl_b, both which will be 
  29. instantiated at the same scope, say main.  I have 
  30. designed some of cl_b's functionality based upon 
  31. being able to use, or see, cl_a's public methods.  
  32. I'm not sure how to structure header files or just 
  33. plain reference cl_a's methods inside cl_b's methods.
  34.  
  35. I could pass an instance of cl_a into cl_b's various 
  36. methods that need visibility of cl_a, but this is rather
  37. tedious, as there are many of those.  It feels much
  38. more logical to want cl_a's public methods to 
  39. essentially seem global to cl_b.
  40.  
  41. I could inherit cl_b from cl_a, but to me semi-frequent 
  42. USE does not justify INHERITANCE, does it?  That would
  43. also make quite a mess and destroy the concept of re-
  44. usability -- a complex network of "uses" relationships
  45. implemented as inheritance would create a web resembling
  46. a procedural design (sort of).
  47.  
  48. I could instantiate (dynamically or not) cl_a inside 
  49. any method in cl_b that needs to see cl_a, but then 
  50. this turns from a "uses" relationship to a "has" 
  51. relationship.  Well, fine, except I'd like to know how
  52. to implement a "uses" relationship.  Further, cl_a is
  53. something of a utility class, and it is used (thus 
  54. would be instantiated) frequently enough that this would 
  55. seem rather excessive and of poor design.  Again, I feel
  56. as though having cl_a's public methods appear globally
  57. visible to cl_b is the best way to go.
  58.  
  59. I could declare class cl_b to be a friend to class cl_a,
  60. but this is a cheap fix.  There is no excuse for letting
  61. cl_b have access to all of cl_a when all it needs is 
  62. access to cl_a's public methods.
  63.  
  64. I'm unclear enough to have tried to just manipulate my
  65. header files, but have been unsuccessful thus far.  Is
  66. this an angle that I can approach this problem with?
  67.  
  68. Any tips are kindly appreciated.
  69.  
  70.  
  71. --
  72. ---
  73.    |-)    paul
  74.  
  75. "The wise person knows that it is better to sit fishing on the banks
  76. of a remote mountain stream than to be emperor of the whole world."
  77.